//
//  FirstViewController.m
//  07-界面通信
//
//  Created by 402030900@qq.com on 16/7/22.
//  Copyright © 2016年 402030900@qq.com. All rights reserved.
//

#import "FirstViewController.h"
#import "SecondViewController.h"
// @class 修饰类,引入头文件中,可以避免掉,头文件的循环导入
// 只声明,用到了这个类,但是.h中不需要引入
// 在 .m中去import
@class FirstViewController;
#warning  签订协议
@interface FirstViewController ()<passValue>
@property(nonatomic,strong)UILabel * titleLabel;
@property(nonatomic,strong)FirstViewController * first;
@end

@implementation FirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // BaseViewController 基类 进行统一修改(例:坐标系,背景颜色等)
    self.view.backgroundColor = [UIColor whiteColor];
    
    //label
    _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 175, 50)];
    _titleLabel.text = @"大王叫我来巡山";
    _titleLabel.backgroundColor = [UIColor colorWithRed:1.000 green:0.910 blue:0.742 alpha:1.000];
    [self.view addSubview:_titleLabel];
    // button
    UIButton * button = [UIButton buttonWithType:(UIButtonTypeSystem)];
    [button setFrame:CGRectMake(100, 300, 100, 50)];
    [button setTitle:@"按钮" forState:(UIControlStateNormal)];
    [button addTarget:self action:@selector(clickButton:) forControlEvents:(UIControlEventTouchUpInside)];
    button.backgroundColor = [UIColor colorWithRed:0.813 green:0.668 blue:1.000 alpha:1.000];
    [self.view addSubview:button];
    // 界面通信
    // 1.属性传值 从前往后 想传递的值作为后一个页面的属性
    // 从后往前传值 (获取FirstVC)
    // 2.协议传值 delegate
    // (1)声明协议2.h -> 声明代理人2.h -> 签代理1,m -> 签协议1.m -> 实现方法1.m -> 传值2.m
    // 声明代理人: @property(nonatomic,weak)id<passValue>delegate;
    // 3.关于navigation控制器的释放
    // navigation中viewControllers数组,数组对对象进行引用计数+ 1
    // 当controller入栈时,则被加入数组,引用计数 + 1
    // 只要不出棧,就不会释放
    // A -> B
    // B -> A B出栈,对应释放
    
    
    // Do any additional setup after loading the view.
}
-(void)clickButton:(UIButton *)button{
    SecondViewController * secVC= [[SecondViewController alloc]init];
#warning  指定代理人
    secVC.delegate = self;
    secVC.passString = _titleLabel.text;
    [self.navigationController pushViewController:secVC animated:YES];
}
#warning 实现协议方法
-(void)passValue:(NSString *)value{
    NSLog(@"%@",value);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
